//
//  KAERootController.m
//  StudyDemo
//
//  Created by 陶涛 on 2018/8/6.
//  Copyright © 2018年 陶涛. All rights reserved.
//

#import "KAERootController.h"
#import "KAEMediaPickerController.h"
#import "KAEImagePickerController.h"
#import "KAEQRCodeController.h"

@interface KAERootController ()

@property (nonatomic, copy) NSArray *dataSource;

@end


static NSString *const  kReuseIdentifier = @"kReuseIdentifier";

@implementation KAERootController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"主页";
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kReuseIdentifier];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSArray *)dataSource {
    if (!_dataSource) {
        _dataSource = @[@"AVAudioPlayer播放音乐",@"使用MPMediaPickerController选择系统音乐",@"使用UIImagePickerController",@"生产二维码"];
    }
    return _dataSource;
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kReuseIdentifier forIndexPath:indexPath];
    
    cell.textLabel.text = self.dataSource[indexPath.row];
    
    return cell;
}


#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 1) {
        KAEMediaPickerController *pickerController = [[KAEMediaPickerController alloc] init];
        [self.navigationController pushViewController:pickerController animated:YES];
    } else if (indexPath.row == 2) {
        KAEImagePickerController *imagePickerController =[[KAEImagePickerController alloc] init];
        [self.navigationController pushViewController:imagePickerController animated:YES];
    } else if (indexPath.row == 3) {
        KAEQRCodeController *qrCodeController = [[KAEQRCodeController alloc] init];
        [self.navigationController pushViewController:qrCodeController animated:YES];
    }
}





@end
